package com.seadragon.app.ksr.util;

import java.io.File;

import org.apache.commons.lang.RandomStringUtils;


public class FileUtils {
	public static String getBaseName(String filename) {
		return filename.substring(0, filename.indexOf('.'));
	}
	
	public static final String createUniqueDirectory(String directory){
		String newDir = RandomStringUtils.randomAlphanumeric(24);
		File file = new File(directory + newDir);
		while(file.exists()){
			newDir = RandomStringUtils.randomAlphanumeric(24);
			file = new File(directory + newDir);
		}
		if(file.mkdir()){
			return newDir;
		}
		return null;
	}
	
	public static final String generateUniqueFilename(String directory){
		String filename = RandomStringUtils.randomAlphanumeric(24);
		File file = new File(directory + filename);
		while(file.exists()){
			filename = RandomStringUtils.randomAlphanumeric(8);
			file = new File(directory + filename);
		}
		return filename;
	}
}
